package cs.servlet;

import cs.utils.DBUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author qiuyihong
 * @description TODO
 * @date 2021/6/20 14:32
 */
@WebServlet(name = "deleteUser", urlPatterns = "/delete")
public class DeleteUser extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");

        String id = request.getParameter("id");
        int i = DBUtils.deleteUser(id);
        if (i == 1) {
            request.setAttribute("msg", "操作成功");
        } else {
            request.setAttribute("msg", "操作失败");
        }
        request.getRequestDispatcher("/").forward(request, response);
    }
}
